package com.qingdai.aspect;

import com.qingdai.annotate.IgnoreJwtCheck;
import com.qingdai.config.RequestConfig;
import com.qingdai.entities.CommonResult;
import io.jsonwebtoken.Claims;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Component
@Aspect
public class JwtAspect {
    @Resource
    private RequestConfig requestConfig;

    @Pointcut("@annotation(com.qingdai.annotate.IgnoreJwtCheck)")
    public void ignoreJwtCheckPointCut() {
    }

    @Around("ignoreJwtCheckPointCut() && @annotation(ignoreJwtCheck)")
    public Object ignoreJwtCheck(ProceedingJoinPoint joinPoint,IgnoreJwtCheck ignoreJwtCheck) throws Throwable {
        System.out.println("aaaaaa");
        if (ignoreJwtCheck.enable()) {
            System.out.println(ignoreJwtCheck.url());
            requestConfig.getAccessUrl().add(ignoreJwtCheck.url());
        }
        return joinPoint.proceed();
    }
}
